<?php
	defined('RUN') or die('No access');
	
	class SupportModel
	{
		private $tables='support';
	    public function getSupports($fields='*')
		{
			return Model::getDataSql("SELECT ".$fields." FROM ".$this->tables." ORDER BY `sort` ASC, `id` DESC");
		}
        public function countRows()
		{
			$sql = "SELECT COUNT(`id`) as `total` FROM ".$this->tables;
			$query = Db::query($sql);
			$result = Query::fetch($query);
			$total = $result['total'];
			
			return $total;
		}
		public function getById($id,$fields='*')
		{
			$condition = array(
					'field' => 'id',
					'value' => $id
				);

			$cat = Model::getData($this->tables, $fields, $condition);
			if ($cat)
				return $cat[0];

			return FALSE;
		}
		public function add($data)
		{
			return Model::insertData($this->tables, $data);
		}

		public function update($data, $id)
		{
			$condition = array(
					'field' => 'id',
					'value' => $id
				);
			
			return Model::updateData($this->tables, $data, $condition);
		}

		public function delete($id)
		{
			$condition = array(
					'field' => 'id',
					'value' => $id
				);

			return Model::deleteData($this->tables, $condition);
		}
	}
